package pe.com.tma.bean;

import java.io.Serializable;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.http.HttpSession;

import org.primefaces.event.DateSelectEvent;

import pe.com.tma.model.Orden;
import pe.com.tma.model.Usuario;
import pe.com.tma.service.OrdenesService;
import pe.com.tma.util.BusquedaGrl;
import pe.com.tma.util.ParametrosGrl;

@ManagedBean(name="ordenBean")
@SessionScoped
public class OrdenesBean implements Serializable{

	private static final long serialVersionUID = 1L;
	
	private List<Orden> ordenes;
	private Usuario user;
	
	private Orden selectedOrd = new Orden();
	
	private OrdenesService srv;
	private BusquedaGrl busc;
	private ParametrosGrl grl = new ParametrosGrl();
	
	public OrdenesBean(){
		FacesContext fCtx = FacesContext.getCurrentInstance();
		HttpSession session = (HttpSession) fCtx.getExternalContext().getSession(true);
		user = (Usuario) session.getAttribute("user");
		busc =  new BusquedaGrl();
		busc.setFecHasta(grl.getFechaActual());
		busc.setFecDesde(grl.getFechaActual());
		srv = new OrdenesService();
		//ordenes = srv.ObtenerOrdenes(user);
		
	}
	
	public void buscar(ActionEvent actionEvent){
		
		ordenes = srv.ObtenerOrdenes(user, busc);
	}

	public void handleDatefecDesde(DateSelectEvent evt){
		busc.setFecDesde(evt.getDate());
	}
	
	public List<Orden> getOrdenes() {
		return ordenes;
	}

	public void setOrdenes(List<Orden> ordenes) {
		this.ordenes = ordenes;
	}

	public BusquedaGrl getBusc() {
		return busc;
	}

	public void setBusc(BusquedaGrl busc) {
		this.busc = busc;
	}

	public Orden getSelectedOrd() {
		return selectedOrd;
	}

	public void setSelectedOrd(Orden selectedOrd) {
		this.selectedOrd = selectedOrd;
	}

	
}
